import http from "@/api";

const baseUrl: string = "/sys/sys_dept";

export interface SysDeptInfoResult {
  id: string;
  deptName: string;
  parentId: string;
  remark?: string;
  createTime?: string;
  updateTime?: string;
  children: SysDeptInfoResult[];
}

export const getSysDeptTree = () => {
  return http.get<SysDeptInfoResult[]>(baseUrl + `/tree`, {}, { loading: false });
};

export const getSysDeptInfo = (id: string | undefined) => {
  return http.get<SysDeptInfoResult>(baseUrl + `/info/` + id, {}, { loading: false });
};

export interface SysDeptSaveParam {
  deptName: string;
  parentId: string;
  remark?: string;
}

export interface SysDeptUpdateParam {
  id: string;
  deptName: string;
  parentId: string;
  remark?: string;
}

export const updateSysDept = (param: SysDeptUpdateParam) => {
  return http.post(baseUrl + `/update`, param);
};

export const saveSysDept = (param: SysDeptSaveParam) => {
  return http.post(baseUrl + `/save`, param);
};

export const deleteSysDept = (id: string) => {
  return http.post(baseUrl + `/delete/` + id);
};
